package com.aos.iot.socket.common.parser;


import cn.hutool.core.lang.Dict;
import cn.hutool.core.util.StrUtil;
import com.aos.iot.protocol.hll.util.CodeUtil;

import java.util.List;

public interface DataParser {

    Dict encode(String payload);

    List<String> encodeItems();

    String decode(Dict data);

    List<String> decodeItems();

    String formatLog(Dict data, List<String> items);

    String cmd();

    String protocol();

    default String sub(String content, int fromIndexInclude, int toIndexExclude, boolean isHigh, String defaultValue) {
        if(StrUtil.length(content) > fromIndexInclude && StrUtil.length(content) >= toIndexExclude) {
            String res = StrUtil.sub(content, fromIndexInclude, toIndexExclude);
            return isHigh ? CodeUtil.highRotation(res) : res;
        }
        return defaultValue;
    }
}
